import axios from 'axios';
import { message } from 'antd';

const token = sessionStorage.getItem('token');
const instance = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 1000,
    headers: {
        'token': token
    }
});
instance.interceptors.response.use(function(res){
    if (res.data.status == 400){
        message.warn(res.data.errMsg);
    } else if (res.data.status == 401){
        message.info('请重新登录');
        this.props.history.push('/');
    }
    return res;
},function(err){
    message.error('接口异常');
    return Promise.reject(err);
})

export default instance;